<?php include '../init.php'; 

	$pid = empty($_GET['pid'])? 0: $_GET['pid'] ;
	if(empty($_POST['name'])){
		$sql = 'select `id`,`name`,`pid`,`path`,`display` from category where pid = '.$pid;
	}else{
		$sql =  'select `id`,`name`,`pid`,`path`,`display` from category where name  like "%'.htmlentities($_POST['name']).'%"   ';
	}
	
	// echo $sql;exit;

	$result = page($sql);
	// var_dump($result);
	$user_list = $result[1];
	$page = $result[0];

	//通过父级的id,查询父级的pid	
	$sql ='select pid from category where id ='.$pid;
	$list = query($sql);
	// var_dump($list);exit;

?>

 <!doctype html>
 <html lang="en">
 <head>
 	<meta charset="UTF-8">
 	<title>Document</title>
			<link rel="stylesheet" type="text/css" href="<?= CSS ?>index.css">
	<link rel="stylesheet" href="<?= PUB_CSS?>commedn.css">
 </head>
 <body>
 	<div class="container">
	    <div id="search">
	      <form action="index.php" method='post'>
	      	 Category Name : <input type="text" name="name" class='search'>
	      	<input class="button" type="submit" value="Search" >
	      </form>
	    </div>
	</div>
	<a href="index.php?pid<?= $list[0]['pid']?>">[ 返回上一级分类 ]</a>
 	<table class='table'>
 		<tr>
 			<th>编号</th>	
 			<th>分类名</th>	
 			<th>PID</th>	
 			<th>PATH</th>	
 			<th>Display</th>	
 			<th>操作</th>	
 		</tr>
		<?php if(empty($user_list)): ?>
			<tr><td colspan=10>找不到您搜索的内容......</td></tr>
		<?php else: ?>
 		<?php foreach($user_list as $v): ?>
 			<tr>
				<td><?= $v['id']?></td>
				<td><?= $v['name']?></td>
				<td><?= $v['pid']?></td>
				<td><?= $v['path']?></td>
				<td><a href="action.php?bz=display&id=<?= $v['id']?>&display=<?=$v['display']?>"><?= $v['display']==1?'显示':'隐藏';     ?></a>
				</td>

				<td>
					<a href="index.php?pid=<?= $v['id'] ?>">查看子分类</a>
					<a href="add.php?id=<?= $v['id'] ?>&path=<?= $v['path']?>">添加子分类</a>
					<a href="edit.php?id=<?= $v['id'] ?>">编辑</a>
					<a href="action.php?bz=del&id=<?= $v['id']?>">删除</a>
				</td>
 			</tr>
 		<?php endforeach; ?>
 	<?php endif; ?>	
 	</table>
 	<?= $page ?>
 </body>
 </html>